<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>平台管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
	<link rel="stylesheet" href="/css/plat-style.css" media="all">
	<style>
		thead tr th{text-align: center!important;font-weight: bold!important;}
		tr td{text-align: center!important;}
		.layui-table img {
			width: auto;
			height: auto;
			max-width: 100% !important;
			max-height: 100%;
		}
		.layui-table a img {
			width: auto;
			height: auto;
			max-width: 100% !important;
			max-height: 100%;
		}
		.operation button{
			margin-bottom: 5px;
		}
	</style>
</head>
<body>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<form action="/order/refund" id="seachFrom" class="layui-form">
					<div class="layui-card-body">
						<%-- 查询条件设置 --%>
						<div class="layui-container" style="padding-bottom: 50px">
							<div class="layui-col-md12">
								<div class="layui-col-md4">
									<div class="layui-col-sm3" style="line-height: 38px">订单编号：</div>
									<div class="layui-col-sm7">
										<input type="text" name="orderCode" class="layui-input" value="${refund.orderCode}" placeholder="订单编号">
									</div>
								</div>
								<div class="layui-col-md4">
									<div class="layui-col-sm3" style="line-height: 38px">状态：</div>
									<div class="layui-col-sm7">
										<select name="status" class="select">
											<option value="">请选择</option>
											<option value="1" ${refund.status == 1?'selected="selected"':'' }>退款申请中</option>
											<option value="2" ${refund.status == 2?'selected="selected"':'' }>退款成功</option>
											<option value="3" ${refund.status == 3?'selected="selected"':'' }>退款驳回</option>
											<option value="4" ${refund.status == 4?'selected="selected"':'' }>退款取消</option>
										</select>
									</div>
								</div>
								<div class="layui-col-md4">
									<div class="layui-col-sm3">
										<button class="layui-btn layui-btn" type="submit">查询</button>
									</div>
								</div>
							</div>
						</div>
						<div class="layui-col-md12"><hr></div>
						<%-- 数据展示 --%>
						<table class="layui-table">
							<thead>
							<tr>
								<th>订单号</th>
								<th>退款编号</th>
								<th>退款金额</th>
								<th>退款积分</th>
								<th>返还方式</th>
								<th>退款方式</th>
								<th>退款理由</th>
								<th>退款图片</th>
								<th>驳回理由</th>
								<th>申请时间</th>
								<th>退款状态</th>
								<th>审核时间</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody>
							<c:forEach items="${pageInfo.records}" var="l">
								<tr>
									<td>${l.orderCode }</td>
									<td>${l.refundCode }</td>
									<td>${l.refundMoney }</td>
									<td>${l.refundPoint }</td>
									<td>
										<c:if test="${l.refundType == 1 }">原路返还</c:if>
										<c:if test="${l.refundType == 2 }">人工处理</c:if>
									</td>
									<td>
										<c:if test="${l.applyType == 1 }">仅退款</c:if>
										<c:if test="${l.applyType == 2 }">退款退货</c:if>
									</td>
									<td>${l.refundReason }</td>
									<td>
										<c:forEach items="${l.refundImgList }" var="img">
											<a target="_blank" href="${img }">
												<img  src="${img }" style="width: 60px;height: 60px;margin-bottom: 5px"/>
											</a>
										</c:forEach>
									</td>
									<td>${l.rejectRemark }</td>
									<td><fmt:formatDate value="${l.createTime}"
														pattern="yyyy-MM-dd HH:mm"></fmt:formatDate></td>
									<td>
										<c:if test="${l.status == 1 }">退款申请中</c:if>
										<c:if test="${l.status == 2 }">退款成功</c:if>
										<c:if test="${l.status == 3 }">退款驳回</c:if>
										<c:if test="${l.status == 4 }">退款取消</c:if>
									</td>
									<td><fmt:formatDate value="${l.checkTime}"
														pattern="yyyy-MM-dd HH:mm"></fmt:formatDate></td>
									<td class="operation">
										<c:if test="${l.status == 1 }">
											<button data-id="${l.id}" data-type="rejectThis" type="button"
													class="layui-btn layui-btn-sm layui-btn-warm rejectThis">驳回</button><br>
											<button data-id="${l.id}" data-type="passThis" type="button"
													class="layui-btn layui-btn-sm layui-btn-normal passThis">通过</button>
										</c:if>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
						<div class="test-table-reload-btn" style="margin-top: 10px;">
							<%@include file="../paging.jsp" %>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
	layui.config({
		base: '/layuiadmin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	}).use(['index','form'], function(){
		var $ = layui.$,layer = layui.layer,form = layui.form,element = layui.element;
		form.render('select');
		element.render();

		var active = {
			//驳回退款申请
			rejectThis:function(id){
				layer.prompt({title: '驳回退款申请', formType: 2}, function(text, index){
					$.ajax({
						type: 'post',
						url: '/order/handleRefundReject',
						data: {'refundId': id,'rejectRemark':text},
						dataType: 'json',
						success: function (data) {
							if (data.status) {
								layer.msg(data.desc);
								setTimeout(function () {
									window.location.reload();
								}, 1000)
							} else {
								layer.msg(data.desc);
							}
						},
						error: function (a,b,c) {
							layer.msg("请检查页面信息是否正确");
						}
					});
				});
			},
			//通过退款申请
			passThis:function (id) {
				layer.confirm('确定操作吗？', function(){
					$.ajax({
						url: "/order/handleRefundSuccess",
						data: {'refundId': id},
						dataType: "json",
						type: "post",
						success: function (data) {
							if (data.status) {
								layer.msg(data.desc);
								setTimeout(function () {
									window.location.reload();
								}, 1000)
							} else {
								layer.msg(data.desc);
							}
						}
					})
				});
			}
		};

		//同意退款申请触发事件
		$('.passThis').on('click', function(){
			var passThis = $(this).data('type');
			var id = $(this).data('id');
			active[passThis] && active[passThis].call(this,id);
		});
		//驳回退款触发事件
		$('.rejectThis').on('click', function(){
			var rejectThis = $(this).data('type');
			var id = $(this).data('id');
			active[rejectThis] && active[rejectThis].call(this,id);
		});
	});
</script>
</body>
</html>